using System;
namespace Gl.SettingsManager
{
	public class Int16ValidatorAttribute : NumericValidatorBaseAttribute
	{
		private short _minValue = 0;
		private short _maxValue = 0;
		private short _defaultValue = 0;

		public short DefaultValue
		{
			get { return _defaultValue; }
			set { _defaultValue = value; }
		}

		public Int16ValidatorAttribute(short minValue, short maxValue)
		{
			_maxValue = maxValue;
			_minValue = minValue;
		}

		public override void Validate(ref object value)
		{
			short valueShort = Convert.ToInt16(value);
			bool valid = false;

			if (CheckMaximum && (_maxValue < valueShort))
				valid = false;

			if (CheckMinimum && (_minValue > valueShort))
				valid = false;

			if (!valid)
			{
				if (ThrowExceptionOnNotValid)
					throw new SettingsException(Exceptions.NotValidValue,
						GetType().FullName);
				else
					value = _defaultValue;
			}
		}
	}
}
